#!/usr/bin/env node


//Node.js 可执行文件的路径
//脚本的路径

const log = console.log,
      arg = process.argv[2];

if(typeof(arg) === 'undefined' ||
    arg === '--help' ||
    arg === '-h') {
  help();
} else {
  calc();
}

// if(process.argv.length > 3) {
//   process.argv = process.argv.slice(0, 3)
// }

function help() {
  log('\
      usage: cmd-name [OPTION] [expression]\n\
      evaluate the expression.\n\
      \n\
      Mandatory arguments to long options are mandatory for short options too.\n\
      -h, --help output help information and exit');
}


function calc() {
  try {
    log(`${arg} = ${eval(arg)}`);
  } catch(e) {
    console.error(`${arg} 不是合法的数学表达式！`);
  }
}    